<?php

namespace App\Http\Controllers\Test;

use Illuminate\Http\Request;
use Biz\Jobs\SiteEmailSendJob;
use Biz\Jobs\SystemEmailSendJob;
use Biz\Models\Site\SitePaperFull;
use Biz\Services\User\UserService;
use Illuminate\Support\Facades\Mail;
use Biz\Constants\ContainerConstants;
use Biz\Models\Site\SitePaperAbstract;
use Biz\Mailers\Site\SitePaperFullPassedMail;
use Biz\Mailers\Site\SitePaperFullRefuseMail;
use Biz\Mailers\Site\SitePaperFullReviewMail;
use Biz\Mailers\Site\SitePaperFullReviseMail;
use Biz\Mailers\Site\SiteUserMemberRegisterMail;
use Biz\Mailers\Site\SitePaperAbstractPassedMail;
use Biz\Mailers\Site\SitePaperAbstractRefuseMail;
use Biz\Mailers\Site\SitePaperAbstractReviewMail;
use Biz\Mailers\Site\SitePaperAbstractReviseMail;
use Biz\Mailers\Site\SitePaperFullSubmissionMail;
use Biz\Mailers\Site\SitePaperAbstractSubmissionMail;

/**
 * MailController.
 *
 * @license [http://www.85do.com] [杭州永奥网络科技有限公司]
 * @copyright Copyright (c) 2018-2026 Hangzhou Yongao Technology Co., Ltd. All rights reserved.
 */
class MailController extends Controller
{
    /**
     * @var mixed
     */
    protected $service;

    /**
     * RepositoryController constructor.
     *
     * @param UserService $service
     */
    public function __construct(UserService $service)
    {
        $this->service = $service;

        $this->middleware('auth:api');
        $this->middleware('app-auth:app_site');
        $this->middleware('app-authorize');
        $this->middleware('scopes:user_client,app_site');
    }

    /**
     * Home.
     *
     * @return string
     */
    public function index(Request $request)
    {
        //dd(app('queue'));
//        $request->request->add([
//            'site_id' => 1,
//        ]);

        $user       = $this->service->find(7);

        //$tags = new UserMemberTags($userMember);
        //$user->email = "jmjones@163.com";

        //Mail::to($user)->send(new SiteUserMemberRegisterMail($user));
        //Mail::send(new SiteUserMemberRegisterMail($user));
        //$mail = new SiteUserMemberRegisterMail($user);
        //dispatch(new MailDispatcher($mail));

        //dd(app('bizClient'));
        //dd(app('bizApp'));
        //dd(app('bizAppSite'));
        //dd(ContainerConstants::BIZ_APP_SITE);
        //dd(app('app')->has(ContainerConstants::BIZ_APP_SITE));

        $abstract = SitePaperAbstract::find(1);
//        $mail       = new SitePaperAbstractSubmissionMail($abstract);
//        dispatch(new SiteEmailSendJob($mail));
        //Mail::send(new SitePaperAbstractSubmissionMail($abstract));
//        Mail::send(new SitePaperAbstractPassedMail($abstract));
//        Mail::send(new SitePaperAbstractRefuseMail($abstract));
//        Mail::send(new SitePaperAbstractReviewMail($abstract));
//        Mail::send(new SitePaperAbstractReviseMail($abstract));
//        Mail::send(new SitePaperAbstractSubmissionMail($abstract));

        $full = SitePaperFull::find(1);
        Mail::send(new SitePaperFullPassedMail($full));
        Mail::send(new SitePaperFullRefuseMail($full));
        Mail::send(new SitePaperFullReviewMail($full));
        Mail::send(new SitePaperFullReviseMail($full));
        Mail::send(new SitePaperFullSubmissionMail($full));

        // 直接发送
        //return $this->testSend($user);

        // 队列发送
        //return $this->testQueueSend($user);

        // 直接预览
        //return $this->testRender($user);
    }

    /**
     * 直接发送
     *
     * @param $user
     *
     * @return string
     */
    public function testRender($user)
    {
        $userMember = $user->member;

        return new SiteUserMemberRegisterMail($userMember);
    }

    /**
     * 直接发送
     *
     * @param $user
     *
     * @return string
     */
    public function testSend($user)
    {
        $userMember = $user->member;
        Mail::send(new SiteUserMemberRegisterMail($userMember));

        return '直接发送成功';
    }

    /**
     * 测试队列发送
     *
     * @param $user
     *
     * @return string
     */
    public function testQueueSend($user)
    {
        $userMember = $user->member;
        $mail       = new SiteUserMemberRegisterMail($userMember);
        dispatch(new SystemEmailSendJob($mail));

        return '队列发送成功';
    }
}
